# Filters added to this controller apply to all controllers in the application.
# Likewise, all the methods added will be available for all controllers
require "common"
require "hpricot"
#require "russian"

class ApplicationController < ActionController::Base
	include AuthenticatedSystem
  #include ExceptionNotifiable
  include SimpleCaptcha::ControllerHelpers
  helper :all # include all helpers, all the time

  # See ActionController::RequestForgeryProtection for details
  # Uncomment the :secret if you're not using the cookie session store
  protect_from_forgery # :secret => '442f43ba2eaa7148da62649074a1d92d'
  
  theme :get_theme
  
  def admin_required
    logged_in? && current_user.admin? || access_denied
  end
  
  def ajax(&block)
    render(:update, &block)
  end
  
  def get_theme
  	logged_in? ? current_user.theme : 'default'
  end
  
  private
  
  def local_request?
	  return false if RAILS_ENV == 'production'
	  true
	end

	def render_404
  	respond_to do |type|
  		type.html { render :file => "#{RAILS_ROOT}/public/404.html", :status => "404 Not Found", :layout=>false }
  		type.all  { render :nothing => true, :status => "404 Not Found" }
  	end
  end
  
  protected

  # Will either fetch the current account or return nil if none is found
  def current_account
    @account ||= User.find_by_login(current_subdomain)
  end
  # Make this method visible to views as well
  helper_method :current_account

end
